package com.gxa.jjty.cjr.service.impl;

import com.gxa.jjty.cjr.service.SmsService;
import com.gxa.jjty.core.exception.BusinessException;
import com.gxa.jjty.core.util.SendSms;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.concurrent.TimeUnit;

/**
 * @author NITRO
 */

@Service("smsService")
@Transactional(rollbackFor = Throwable.class)
public class SmsServiceImpl implements SmsService {


    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    public static final String LOGIN_SMS="login_:";
    @Override
    public String sendLoginSms(String phone) throws BusinessException {

        String msgCode = SendSms.getMsgCode();
        System.out.println(msgCode);
        ValueOperations<String, Object> stringOps = redisTemplate.opsForValue();
        stringOps.set(LOGIN_SMS+phone,msgCode,30, TimeUnit.MINUTES  );
        return msgCode;
    }
}
